using System.ComponentModel.DataAnnotations;

namespace KnowledgeQA.Models.DTOs
{
    /// <summary>
    /// 聊天会话DTO
    /// </summary>
    public class ChatSessionDTO
    {
        /// <summary>
        /// 会话ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 会话标题
        /// </summary>
        public string Title { get; set; } = string.Empty;

        /// <summary>
        /// 会话描述
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string? UserId { get; set; }

        /// <summary>
        /// 会话状态
        /// </summary>
        public string Status { get; set; } = string.Empty;

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        public string? ModelName { get; set; }

        /// <summary>
        /// 最后活跃时间
        /// </summary>
        public DateTime LastActiveAt { get; set; }

        /// <summary>
        /// 消息数量
        /// </summary>
        public int MessageCount { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }
    }

    /// <summary>
    /// 聊天消息DTO
    /// </summary>
    public class ChatMessageDTO
    {
        /// <summary>
        /// 消息ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 会话ID
        /// </summary>
        public int SessionId { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        public string MessageType { get; set; } = string.Empty;

        /// <summary>
        /// 消息内容
        /// </summary>
        public string Content { get; set; } = string.Empty;

        /// <summary>
        /// 消息序号
        /// </summary>
        public int MessageIndex { get; set; }

        /// <summary>
        /// 父消息ID
        /// </summary>
        public int? ParentMessageId { get; set; }

        /// <summary>
        /// 消息状态
        /// </summary>
        public string Status { get; set; } = string.Empty;

        /// <summary>
        /// 处理时间（毫秒）
        /// </summary>
        public long? ProcessingTime { get; set; }

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        public string? ModelName { get; set; }

        /// <summary>
        /// 检索到的文档块信息
        /// </summary>
        public List<RetrievedChunkInfo> RetrievedChunks { get; set; } = new List<RetrievedChunkInfo>();

        /// <summary>
        /// 错误信息
        /// </summary>
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 用户反馈
        /// </summary>
        public string UserFeedback { get; set; } = string.Empty;

        /// <summary>
        /// 用户反馈备注
        /// </summary>
        public string? FeedbackNote { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
    }

    /// <summary>
    /// 检索到的文档块信息
    /// </summary>
    public class RetrievedChunkInfo
    {
        /// <summary>
        /// 文档块ID
        /// </summary>
        public int ChunkId { get; set; }

        /// <summary>
        /// 文档ID
        /// </summary>
        public int DocumentId { get; set; }

        /// <summary>
        /// 文档标题
        /// </summary>
        public string DocumentTitle { get; set; } = string.Empty;

        /// <summary>
        /// 块内容
        /// </summary>
        public string Content { get; set; } = string.Empty;

        /// <summary>
        /// 相关度评分
        /// </summary>
        public double RelevanceScore { get; set; }

        /// <summary>
        /// 块序号
        /// </summary>
        public int ChunkIndex { get; set; }
    }

    /// <summary>
    /// 创建会话请求DTO
    /// </summary>
    public class CreateSessionRequest
    {
        /// <summary>
        /// 会话标题
        /// </summary>
        [Required]
        [MaxLength(200)]
        public string Title { get; set; } = string.Empty;

        /// <summary>
        /// 会话描述
        /// </summary>
        [MaxLength(500)]
        public string? Description { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        [MaxLength(100)]
        public string? UserId { get; set; }

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        [MaxLength(100)]
        public string? ModelName { get; set; }

        /// <summary>
        /// 会话配置
        /// </summary>
        public Dictionary<string, object>? Configuration { get; set; }
    }

    /// <summary>
    /// 发送消息请求DTO
    /// </summary>
    public class SendMessageRequest
    {
        /// <summary>
        /// 会话ID
        /// </summary>
        [Required]
        public int SessionId { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        [Required]
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 父消息ID
        /// </summary>
        public int? ParentMessageId { get; set; }

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        [MaxLength(100)]
        public string? ModelName { get; set; }

        /// <summary>
        /// 模型参数
        /// </summary>
        public Dictionary<string, object>? ModelParameters { get; set; }
    }

    /// <summary>
    /// 问答请求DTO
    /// </summary>
    public class AskQuestionRequest
    {
        /// <summary>
        /// 问题内容
        /// </summary>
        [Required]
        public string Question { get; set; } = string.Empty;

        /// <summary>
        /// 上下文信息
        /// </summary>
        public string? Context { get; set; }

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        [MaxLength(100)]
        public string? ModelName { get; set; }

        /// <summary>
        /// 模型参数
        /// </summary>
        public Dictionary<string, object>? ModelParameters { get; set; }

        /// <summary>
        /// 检索参数
        /// </summary>
        public RetrievalParameters? RetrievalParameters { get; set; }
    }

    /// <summary>
    /// 检索参数
    /// </summary>
    public class RetrievalParameters
    {
        /// <summary>
        /// 检索的文档块数量
        /// </summary>
        public int TopK { get; set; } = 5;

        /// <summary>
        /// 最小相关度阈值
        /// </summary>
        public double MinRelevanceScore { get; set; } = 0.1;

        /// <summary>
        /// 是否包含元数据
        /// </summary>
        public bool IncludeMetadata { get; set; } = true;

        /// <summary>
        /// 文档分类过滤
        /// </summary>
        public List<int>? CategoryIds { get; set; }

        /// <summary>
        /// 文档标签过滤
        /// </summary>
        public List<string>? Tags { get; set; }
    }

    /// <summary>
    /// 问答响应DTO
    /// </summary>
    public class AskQuestionResponse
    {
        /// <summary>
        /// 答案内容
        /// </summary>
        public string Answer { get; set; } = string.Empty;

        /// <summary>
        /// 检索到的文档块信息
        /// </summary>
        public List<RetrievedChunkInfo> RetrievedChunks { get; set; } = new List<RetrievedChunkInfo>();

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        public string? ModelName { get; set; }

        /// <summary>
        /// 处理时间（毫秒）
        /// </summary>
        public long ProcessingTime { get; set; }

        /// <summary>
        /// 置信度评分
        /// </summary>
        public double ConfidenceScore { get; set; }

        /// <summary>
        /// 是否使用了RAG
        /// </summary>
        public bool UsedRAG { get; set; }
    }

    /// <summary>
    /// 用户反馈请求DTO
    /// </summary>
    public class UserFeedbackRequest
    {
        /// <summary>
        /// 消息ID
        /// </summary>
        [Required]
        public int MessageId { get; set; }

        /// <summary>
        /// 反馈类型
        /// </summary>
        [Required]
        [MaxLength(20)]
        public string Feedback { get; set; } = string.Empty;

        /// <summary>
        /// 反馈备注
        /// </summary>
        [MaxLength(500)]
        public string? FeedbackNote { get; set; }
    }
} 